/*************************************************************************
Program Name: criminal.cpp
Des: This program will take a database of criminals and insert it into a
binary tree.  Through a series of functions, the program will prune the 
the tree to find out the criminals whos attributes are in the casefile
Author: Alberto De Pena
Due Date: 12/12/09 @ 11:55pm
*************************************************************************/

#include "bst.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

/*************************************************************************
Function Name: MAIN
*************************************************************************/

void main ()
{
	//Open files
	ifstream crimfin("criminal.dat");
	ifstream casefin("casefile.dat");
	ofstream crimfout("criminal.out");

	Bst CriminalList;
	string data, Tip;
	
	
	crimfin >> data;
	while(!crimfin.eof() && data != "FINISHED")
	{
		//Creates an information field
		TreeType Criminal;
		int i = 0;
		int count = 1;
		crimfin >> Criminal.Name;
		if(Criminal.Name != "FINISHED")
		{
			crimfin >> data;
			while(data != "SUSPECT")
			{
				Criminal.Attribute[i++] = data;
				Criminal.AttributeCount = count++;
				crimfin >> data;
			}
			//Inserts the information in to a node
			CriminalList.Insert(Criminal);
			count = 1;
		}
	}
	
	int Case = 1;
	casefin >> Tip;
	while(!casefin.eof() && Tip != "FINISHED")
	{
		//Creates a copy of the tree
		Bst CurrentList(CriminalList);
		casefin >> Tip;
		while(Tip == "TIP")
		{
			casefin >> Tip;
			CurrentList.Prune(Tip);
			casefin >> Tip;
		}
		crimfout << "CASE NUMBER " << Case++ << endl;
		crimfout << "PRIME SUSPECTS ARE..." << endl;

		if(CurrentList.Empty())
			crimfout << "NO SUSPECTS FOR THIS CASE" << endl;
		else
			CurrentList.Print(crimfout);

		crimfout << endl;
	}
	//Close files
	crimfin.close();
	casefin.close();
	crimfout.close();
}